package com.itheima.test.Demo7;

import java.io.*;
import java.sql.Array;
import java.util.Arrays;

/*
9 1 2 5 3 10 4 6 7 8
 */
public class Demo7 {
    public static void main(String[] args) throws IOException {
        //先创建字符缓冲流将数据读取出来
        BufferedReader br = new BufferedReader(new FileReader("day13_字符流\\b.txt"));
        String s = br.readLine();//字符缓冲流读取数据能读取一行,包括空格
        System.out.println(s);
        //关闭资源
        br.close();
        //在对s进行切割
        String[] split = s.split(" ");
        //定义一个数组用来装遍历转换后的字符
        int[] arr = new int[split.length];
        //对数组split进行遍历
        for (int i = 0; i < split.length; i++) {
            int  number = Integer.parseInt(split[i]);
            arr[i] = number;
        }
        //再将arr排序
        Arrays.sort(arr);
        //再将其转换为字符
        System.out.println(Arrays.toString(arr));

        //再用字符缓冲流将其写入文件中
        BufferedWriter bw = new BufferedWriter(new FileWriter("day13_字符流\\c.txt"));
        for (int i = 0; i < arr.length; i++) {
            bw.write(arr[i] + " ");
        }
        bw.close();
    }
}
